package com.tinysand.advert.client.hystrix;

import com.alibaba.fastjson.JSON;
import com.tinysand.advert.client.SponsorClient;
import com.tinysand.advert.exception.AdvertException;
import com.tinysand.advert.support.AdPlan;
import com.tinysand.advert.support.AdPlanGetRequest;
import com.tinysand.advert.support.CommonResponse;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 广告投放系统的服务熔断降级策略
 *
 * Created By TINY
 * Create Time 2020/2/27
 **/
@Component
public class SponsorHystrix implements SponsorClient {

    /**
     * 根据请求参数获取对应的推广计划数据
     *
     * @param request 请求参数包装对象 {@link AdPlanGetRequest}
     * @return 推广计划数据
     * @throws AdvertException 业务异常
     */
    @Override
    public CommonResponse<List<AdPlan>> getAdPlanByIds(
            AdPlanGetRequest request) throws AdvertException {
        return new CommonResponse<>(
                -1, "Feign 调用失败，请求参数："
                + JSON.toJSONString(request)
        );
    }
}
